package top.tangyh.lamp.care.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.tangyh.lamp.care.mapper.BHl7MedicineMapper;
import top.tangyh.lamp.care.service.BHl7MedicineService;
import top.tangyh.basic.base.service.impl.SuperServiceImpl;
import top.tangyh.lamp.care.manager.BHl7MedicineManager;
import top.tangyh.lamp.care.entity.BHl7Medicine;
import top.tangyh.lamp.care.vo.query.MedicineQueryVO;
import top.tangyh.lamp.care.vo.result.PageOutputDTO;
import top.tangyh.lamp.care.vo.save.BHl7MedicineSaveVO;
import top.tangyh.lamp.care.vo.update.BHl7MedicineUpdateVO;
import top.tangyh.lamp.care.vo.result.BHl7MedicineResultVO;
import top.tangyh.lamp.care.vo.query.BHl7MedicinePageQuery;

import java.util.List;

import static top.tangyh.lamp.common.constant.CommonConstant.YES_NUMBER;

/**
 * <p>
 * 业务实现类
 * 药物表
 * </p>
 *
 * @author zqb
 * @date 2024-08-09 16:23:52
 * @create [2024-08-09 16:23:52] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class BHl7MedicineServiceImpl extends SuperServiceImpl<BHl7MedicineManager, Integer, BHl7Medicine> implements BHl7MedicineService {


    private final BHl7MedicineMapper bHl7MedicineMapper;
    @Override
    public PageOutputDTO<BHl7Medicine> selectPageByQuery(MedicineQueryVO queryVO) {
        IPage<BHl7Medicine> resultPage = bHl7MedicineMapper.selectPageListByQuery(queryVO);
        return new PageOutputDTO<>(resultPage.getTotal(), resultPage.getSize(), resultPage.getCurrent(), resultPage.getRecords());
    }

    @Override
    public List<BHl7Medicine> selectListByQuery(MedicineQueryVO queryVO) {
        List<BHl7Medicine> resultList = bHl7MedicineMapper.selectListByQuery(queryVO);
        return resultList;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(BHl7MedicineSaveVO inVO) {
        BHl7Medicine yxHl7MedicinePO = new BHl7Medicine();
        BeanUtil.copyProperties(inVO, yxHl7MedicinePO);
        bHl7MedicineMapper.insert(yxHl7MedicinePO);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void update(BHl7MedicineSaveVO inVO) {
        BHl7Medicine yxHl7MedicinePO = new BHl7Medicine();
        BeanUtil.copyProperties(inVO, yxHl7MedicinePO);
        bHl7MedicineMapper.updateById(yxHl7MedicinePO);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(Long id) {
        BHl7Medicine yxHl7MedicinePO = new BHl7Medicine();
        yxHl7MedicinePO.setId(id);
        yxHl7MedicinePO.setIsDeleted(YES_NUMBER);
        bHl7MedicineMapper.updateById(yxHl7MedicinePO);
    }

}


